from django.db import models

from fbase.models import Object
from utils.timezone import astimezone2cst


class ReportBase(Object):
    human_cost = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='人力成本')
    business_cost = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='业务成本')
    income = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='收入')
    total_cost = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='总成本')
    total_income = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='总收益')
    report_time = models.DateTimeField(auto_now=True, verbose_name='统计时间')
    month = models.DateTimeField(verbose_name='截止月份')

    class Meta:
        abstract = True


class BusinessLineReportBase(ReportBase):
    businessline = models.ForeignKey('organization.BusinessLine', on_delete=models.PROTECT, verbose_name='业务线')
    businessdept = models.ForeignKey('organization.BusinessDept', on_delete=models.PROTECT, verbose_name='事业部')

    class Meta:
        abstract = True

    def __str__(self):
        return '{}:{}:{}'.format(
            self.businessdept.name,
            self.businessline.name,
            astimezone2cst(self.month)
        )


class BusinessDeptReportBase(ReportBase):
    businessdept = models.ForeignKey('organization.BusinessDept', on_delete=models.PROTECT, verbose_name='事业部')

    class Meta:
        abstract = True

    def __str__(self):
        return '{}:{}'.format(
            self.businessdept.name,
            astimezone2cst(self.month)
        )
